package entries;

import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @author zharikhin
 *
 */
public class User {
    
    private long id;
    private String login;
    private String password;
    private String email;
    private String firstName;
    private String lastName;
    private Date birthDay;
    private Role role;
    private int age;

    public User() {}

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(Date birth) {
        this.birthDay = birth;
    }
    
    public Role getRole (){
        return role;
    }

    public void setRole(Role newRole) {
        this.role = newRole;
    }

    public int getAge(){

        Calendar cal = Calendar.getInstance();
        cal.setTime(birthDay);

        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int d = cal.get(Calendar.DAY_OF_MONTH);

        cal = new GregorianCalendar(y, m, d);

        Calendar now = Calendar.getInstance();
        int res = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR);

        if((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH))
                || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)
                && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH)))
        {
            res--;
        }
        age = res;
        return age;
    }

    public void newOperation(){}

}
